package br.com.intelsys.basics.net;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

public class NetServiceTest {
	private NetService netService;

	private static final String IP_ADDR = "187.13.219.241";
	private static final long IP_LONG = 3138247665L;
	private static final int MASK = 30;
	private static final String IP_OUT_ADDR = "187.13.219.244";

	@Before
	public void setUp() {
		netService = new NetService();
	}

	@Test
	public void testConvertIPLongToAddr() {
		assertEquals(NetService.longToIp(IP_LONG), IP_ADDR);
	}

	@Test
	public void testConvertIPAddrToLong() {
		assertEquals(NetService.ipToLong(IP_ADDR), IP_LONG);
	}

	@Test
	public void testIpLongRange() {
		assertTrue(NetService.isIpInRange(IP_LONG, (byte) MASK, IP_ADDR));
	}

	@Test
	public void testIpLongOutRange() {
		assertFalse(NetService.isIpInRange(IP_LONG, (byte) MASK, IP_OUT_ADDR));
	}

	@Test
	public void testIpStringRange() {
		assertTrue(NetService.isIpInRange(IP_ADDR, MASK, IP_ADDR));
	}

	@Test
	public void testIpStringOutRange() {
		assertFalse(NetService.isIpInRange(IP_ADDR, MASK, IP_OUT_ADDR));
	}

	@Test
	public void testIpStringSubRange() {
		assertTrue(NetService.isIpInRange(IP_ADDR + "/" + MASK, IP_ADDR));
	}

	@Test
	public void testIpStringSubOutRange() {
		assertFalse(NetService.isIpInRange(IP_ADDR + "/" + MASK, IP_OUT_ADDR));
	}
}
